import $http from "@/services";
export default {
    state: {
        levelLists: [],
        levelTotal: 0,
        levelDetail: null,
        levelSearch: {
            page: 1,
            size: 5,
            queryData: {}
        }
    },
    // 赋值
    reducers: {
        setLevelLists(state, { payload }) {
            return { ...state, levelLists: payload }
        },
        setLevelTotal(state, { payload }) {
            return { ...state, levelTotal: payload }

        },
        setLevelDetail(state, { payload }) {
            return { ...state, levelDetail: payload }
        },
        setLevelSearch(state, { payload }) {
            return { ...state, levelSearch: { ...state.levelSearch, ...payload } };
        }
    },
    effects: {
        // 初始化数据，获取数据
        *initLevelContent({ payload }, { put, call, select }) {
            // 重新处理请求关系
            yield put({
                type: "setLevelSearch",
                payload
            })
            const { levelSearch } = yield select(state => state.level);
            //请求数据
            const { data, msg } = yield call($http.getLevelList, levelSearch);
            yield put({
                type: "setLevelLists",
                payload: data.list
            })
            console.log(data)
            yield put({
                type: "setLevelTotal",
                payload: data.total
            })

        },
        // 重新获取职级详情
        *getDetailLevel({ payload }, { put, call }) {
            const { data } = yield call($http.getLevelDetail, payload);
            console.log(data)
            if (data) {
                yield put({
                    type: "setLevelDetail",
                    payload: data
                })
                yield put({
                    type: "common/setIsShowDetail",
                    payload: true
                });
            }

        }
    }
}